from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from unittest import runner

# 打开浏览器
driver = webdriver.Chrome()
# 访问的网页
driver.get('http://192.168.1.25/crm')
driver.implicitly_wait(30)
# 最大化窗口
driver.maximize_window()

username = '杨应科'
password = '123456'

# 定位器
username_shuru_locator = (By.NAME,'name')
password_shuru_locator = (By.NAME,'password')
dl_dianji_locator = (By.NAME,'submit')
qiehuan_locator = (By.CSS_SELECTOR,'#widgets > div > div:nth-child(6) > div > div.dash-title > a')
tianjia_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div.pull-right > a')
shurubiaoti_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input')
nr_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tbody > tr:nth-child(7) > td:nth-child(2) > div > div.ke-edit > iframe')
baocun_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div > form > table > tfoot > tr > td > input.btn.btn-primary')

# 执行
driver.find_element(*username_shuru_locator).send_keys(username)
driver.find_element(*password_shuru_locator).send_keys(password)
driver.find_element(*dl_dianji_locator).click()
driver.find_element(*qiehuan_locator).click()
driver.find_element(*tianjia_locator).click()
driver.find_element(*shurubiaoti_locator).send_keys('大家好')
driver.find_element(*nr_locator).send_keys('今天大家请问吃饭')
sleep(3)
driver.find_element(*baocun_locator).click()
sleep(5)
driver.quit()
